export const cellList = {
  top: [
    {
      title: '基本信息',
      color: '#0177fd',
      iconName: 'tongyong-yonghumingtubiao',
      pathName: 'basicInfo',
    },
    {
      title: '个人经历',
      color: '#0177fd',
      iconName: 'nav_profile',
      pathName: 'experience',
    },
    {
      title: '我的组织',
      color: '#f85d25',
      iconName: 'zuzhiguanli',
      pathName: 'organization',
    },
  ],
  bottom: [
    {
      title: '安全性设置',
      color: '#15b6fe',
      iconName: 'suo',
      pathName: 'safety',
    },
    {
      title: '联系我们',
      color: '#ff9873',
      iconName: 'lianxiwomen',
    },
  ],
};

export const sexList = [
  {
    label: '男',
    value: 1,
  },
  {
    label: '女',
    value: 2,
  },
  {
    label: '不公开',
    value: 9,
  },
];
export function getEchoValue(
  currValue: any,
  list: any[],
  type = 'radio',
  defaultpProps?: any
) {
  if (!list) return;
  if (type === 'radio') {
    const value = defaultpProps?.value;
    const label = defaultpProps?.label;
    const currItem = list.find((el) => el[value || 'value'] === currValue);
    if (currItem) {
      return currItem[label || 'label'];
    }
    return '';
  } else {
    // const valArr = currValue ? currValue.split(',') : [];
    const valArr = currValue ? JSON.parse(currValue) : [];
    let strArr: any[] = [];
    valArr.forEach((element: string, index: number) => {
      const value = element[element.length - 1];
      const data = getTreeValue(list, value);
      strArr.push(data?.join('-'));
    });
    return strArr.join(',');
  }
}

// 根据值从树形结构数据中获取从根节点到目标节点的值
// 返回所在分支所有层级的节点label数组
// 主要用于获取个人中心-基本信息中学术专业的回显
function getTreeValue(list: any[], value: string, selList: any[] = []) {
  for (let i = 0; i < list.length; i++) {
    selList.push(list[i].label);
    if (list[i].value === value) {
      return selList;
    }
    let tempList: any[] = [];
    if (list[i].children?.length) {
      tempList = getTreeValue(list[i].children, value, selList) as any[];
    }
    if (tempList?.length) {
      return tempList;
    } else {
      selList.pop();
    }
  }
}
export function getValueIndex(
  currValue: any,
  list: any[],
  defaultpProps?: any
) {
  const value = defaultpProps?.value;
  const currItem = list.findIndex((el) => el[value || 'value'] === currValue);
  if (currItem > -1) {
    return [currItem];
  }
  return [0];
}

export const getLabel = (
  arr: any[],
  value: string,
  level = 0,
  label = ''
): string | undefined => {
  for (let i = 0; i < arr.length; i++) {
    if (arr[i].value === value[level]) {
      label = arr[i].label;
    } else {
      continue;
    }
    level++;
    if (level < value.length) {
      label = label + '/' + getLabel(arr[i].children, value, level, label);
    }
  }
  return label;
};
